﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UoMDetailSetupForm.aspx.cs"
    Inherits="FBKPI.Forms.UoMDetailSetupForm" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        $(document).ready(function () {
            $("#divBrowseUOMSetup").hide();
            $("#divBrowseUOMSetup").dialog({ autoOpen: false, width: 900, height: 420, modal: true, resizable: false });

            $('.date-picker').datepicker({
                changeMonth: true,
                changeYear: true,
                showYear: true,
                showButtonPanel: true,
                dateFormat: 'MM yy',
                onClose: function (dateText, inst) {
                    var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
                    var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
                    $(this).datepicker('setDate', new Date(year, month, 1));
                }
            });

            $("#btn_savedetaildua").click(function () {
                var param = "?";
                var isActive = 'false';

                $('#form1 td input:checked').each(function () {
                    var $cb = $(this);
                    if ($cb.attr('id') == 'chk_activesetup') {
                        isActive = 'true';
                    }
                });

                var listval = "";
                if ($("#txt_listvaluemonthsetup").val() != '')
                    listval = $("#txt_listvaluemonthsetup").val();
                else
                    listval = $("#txt_listvaluesetup").val();

                param = param + "action=save";
                param = param + "&ID=" + $("#hfIdsetup").val();
                param = param + "&Description=" + $("#txt_descriptionsetup").val();
                param = param + "&ListValue=" + listval;
                param = param + "&UoMType=" + $("#txt_uomtypesetup").val();
                param = param + "&isActive=" + isActive;
                param = param + "&UOM=" + $("#txt_uomidsetup").val();
                param = param + "&CurrUser=" + $("#txt_user").val();
                ProcessRequest("UoMDetailHandler.ashx" + param, "#divdetailInputUomDetail", "#KPITable");
                return false;
            });


            

            $("#btn_closedetaildua").click(function () {
                parent.$("#divdetailInputUomDetail").dialog("close");
                return false;
            });

            $("#btn_BrowseUOMSetup").click(function () {
                $("#divBrowseUOMSetup").dialog("option", "title", '<span class="header-text">Select Unit Of Measure</span>');
                $("#divBrowseUOMSetup").dialog("open");
                $('#uomsetup').dataTable({
                    "oLanguage": {
                        "sZeroRecords": "No records to display",
                        "sSearch": "Search"
                    },
                    "bSort": false,
                    "bPaginate": true,
                    "bAutoWidth": true,
                    "bProcessing": true,
                    "bServerSide": true,
                    "bDestroy": true,
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers",
                    "bDeferRender": true,
                    "fnServerData": function (sSource, aoData, fnCallback) {
                        $.ajax({
                            "dataType": 'json',
                            "type": "GET",
                            "url": "../Serializer/UoMSerializer.ashx",
                            "data": aoData,
                            "success": fnCallback
                        });
                    },
                    "aoColumns": [
                        { "mData": "No" },
                        { "mData": "Description" },
                        { "mData": "Format" },
                        { "mData": "isActive" },
                        { "mData": "ID" },
                    ],
                    "aoColumnDefs":
                    [
                        { "fnRender":
                            function (oObj) {
                                return "<a href=\"#\" onclick=\"PickUOM('" + oObj.aData["ID"] + "','" + oObj.aData["Description"] + "', '" + oObj.aData["Format"] + "')\"><img src='../images/ok.png' /></a>";
                            },
                            "aTargets": [4]
                        },
                        { "sClass": "center", "aTargets": [0, 2, 3, 4] },
                        { "fnRender":
                            function (oObj) {
                                if (oObj.aData["isActive"] == 'True') {
                                    return "<img src='../images/check.png' />"
                                }
                                else {
                                    return "<img src='../images/cross.png' />"
                                }
                            },
                            "aTargets": [3]
                        }
                    ]
                });

                //mark selected row
                $('body').on("click", '#uomsetup tbody tr', function () {
                    $('#uomsetup tbody tr').removeClass("row_selected");
                    $(this).addClass("row_selected");
                });
                $(".dataTables_filter input").focus();
                return false;
            });

            PickUOM = function (UOMID, UOMDescription, UoMFormat) {
                if (UoMFormat.toString() == 'Month') {
                    $("#txt_listvaluemonthsetup").show();
                    $("#txt_listvaluesetup").hide();
                    $("#txt_listvaluemonthsetup").val('');
                    $("#txt_listvaluesetup").val('');
                }
                else {
                    $("#txt_listvaluemonthsetup").hide();
                    $("#txt_listvaluesetup").show();
                    $("#txt_listvaluemonthsetup").val('');
                    $("#txt_listvaluesetup").val('');
                }
                $("#txt_uomsetup").val(UOMDescription);
                $("#txt_uomidsetup").val(UOMID);
                $("#txt_uomtypesetup").val(UoMFormat);
                $("#divBrowseUOMSetup").dialog("close");
            }
        });
    </script>
    <style>
        .ui-datepicker-calendar
        {
            display: none;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="categorykpiformarea" class="ui-widget-content padding5px ui-corner-all">
        <table class="dialogTable">
            <tr runat="server" visible="false">
                <td width="140px">
                    ID
                </td>
                <td class="Separator">
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_idsetup" runat="server" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
             <tr>
                <td>
                    Unit of Measure
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_uomsetup" runat="server" ReadOnly="true" Width="400" class="mandatory"></asp:TextBox>
                    <button id="btn_BrowseUOMSetup" class="ui-button ui-state-default">
                        <span class="ui-button ui-icon ui-icon-newwin"></span>
                    </button>
                    <input type="hidden" id="txt_uomidsetup" runat="server" />
                </td>
            </tr>
           
            <tr>
                <td>
                    UoM Type
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_uomtypesetup" runat="server" Width="400" class="mandatory" ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
             <tr runat="server" visible="true" >
                <td>
                    List Value
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_listvaluesetup" runat="server" Width="400" class="mandatory"></asp:TextBox>
                    <asp:TextBox ID="txt_listvaluemonthsetup" runat="server" class="mandatory date-picker"
                        ReadOnly="true"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    Description
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:TextBox ID="txt_descriptionsetup" runat="server" Width="400" class="mandatory"></asp:TextBox>
                </td>
            </tr>
           
            <tr>
                <td>
                    is Active
                </td>
                <td>
                    :
                </td>
                <td>
                    <asp:CheckBox ID="chk_activesetup" Checked="true" runat="server" />
                </td>
            </tr>
        </table>
    </div>
    <br />
   
    <div id="divBrowseUOMSetup" class="ui-widget-content padding5px ui-corner-all">
        <table cellpadding="0" cellspacing="0" border="0" class="display" id="uomsetup">
            <thead>
                <tr>
                    <th>
                        No
                    </th>
                    <th>
                        Description
                    </th>
                    <th>
                        Format
                    </th>
                    <th>
                        is Active
                    </th>
                    <th>
                    </th>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    <br />
    <button id="btn_savedetaildua" class="button save">
        Save
    </button>

    <button id="btn_closedetaildua" class="button close">
        Close
    </button>
    
    <asp:HiddenField ID="hfIdsetup" runat="server" Value="0" />
    </form>
</body>
</html>
